package com.jetpackframework.skin;

import android.app.Application;
import android.view.LayoutInflater;

import androidx.core.view.LayoutInflaterCompat;

import com.jetpackframework.Reflector;

public class SkinInstaller {
    public static void install(Application application, Skin skin) {
        application.registerActivityLifecycleCallbacks(new SkinActivityLifecycleCallBack(SkinManager.getInstance()));
        SkinLayoutInflaterFactory inflaterFactory = new SkinLayoutInflaterFactory();
        try {
            Reflector.with(LayoutInflater.from(application)).field("mFactorySet").set(false);
            LayoutInflaterCompat.setFactory2(LayoutInflater.from(application),inflaterFactory);
        } catch (Reflector.ReflectedException e) {
            e.printStackTrace();
        }
        SkinManager.getInstance().addObserver(inflaterFactory);

    }
}
